package cn.bocweb.spinning.view.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import cn.bocweb.spinning.R;
import cn.bocweb.spinning.model.Bean.ScoreListBean;
import cn.bocweb.spinning.util.DeviceUtil;

/**
 * Created by chenchangxing on 15/12/22.
 */
public class MyIntegralAdapter extends RecyclerView.Adapter {

    List<ScoreListBean.DataBean> mDataBeanList;

    public MyIntegralAdapter(List<ScoreListBean.DataBean> mDataBeanList) {
        this.mDataBeanList = mDataBeanList;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        LayoutInflater inflater = LayoutInflater.from(parent.getContext());
        View view = inflater.inflate(R.layout.item_my_integral, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ViewHolder holder1 = (ViewHolder)holder;
        holder1.mTitle.setText(mDataBeanList.get(position).getTitle());
        if (mDataBeanList.get(position).getType().equals("1")) {
            holder1.mCount.setText("+" + mDataBeanList.get(position).getNum());
        } else {
            holder1.mCount.setText("-" + mDataBeanList.get(position).getNum());
        }
        holder1.mTime.setText(
                DeviceUtil.getTimeForDate(
                        Long.parseLong(mDataBeanList.get(position).getTimeline()) * 1000,
                        System.currentTimeMillis()));
    }

    @Override
    public int getItemCount() {
        return mDataBeanList.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.title)
        TextView mTitle;
        @Bind(R.id.time)
        TextView mTime;
        @Bind(R.id.count)
        TextView mCount;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
